package cn.yueranzs.system.controller;


import cn.yueranzs.login.common.DataUtil;
import cn.yueranzs.response.Result;
import cn.yueranzs.system.dto.role.RoleQueryDto;
import cn.yueranzs.system.pojo.Role;
import cn.yueranzs.system.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author yueranzs
 * @since 2021-11-09
 */
@Api(tags = "角色控制器")
@RestController
@RequestMapping("/system/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @PreAuthorize("hasRole('admin')")
    @ApiOperation(value = "查询角色列表",notes ="根据掺入的参数查询角色列表")
    @GetMapping("/findRoleList")
    public Result findRoleList(RoleQueryDto dto){
        Role role = DataUtil.setData(dto, Role.class);
        return Result.successData(roleService.findRoleList(role));
    }

    @PreAuthorize("hasRole('admin')")
    @ApiOperation(value = "查询已拥有的角色列表",notes ="根据用户编号查询已拥有的角色列表")
    @GetMapping("/hasRoleList/{userId}")
    public Result findRoleList(@PathVariable("userId") Long userId){
        return Result.successData(roleService.hasRoleList(userId));
    }
}

